// SynchroSettingDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FlowChartSoftware.h"
#include "SynchroSettingDlg.h"

int CSynchroSettingDlg::s_choice = 3;
int	CSynchroSettingDlg::s_refreshRate = 1;

// CSynchroSettingDlg dialog

IMPLEMENT_DYNAMIC(CSynchroSettingDlg, CDialog)

CSynchroSettingDlg::CSynchroSettingDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSynchroSettingDlg::IDD, pParent)
{
}

CSynchroSettingDlg::~CSynchroSettingDlg()
{
}

void CSynchroSettingDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Radio(pDX, IDC_RADIO1, s_choice);
	DDX_Text(pDX, IDC_EDIT_REFRESH_RATE, s_refreshRate);
	DDV_MinMaxInt(pDX, s_refreshRate, 1, 30);
}


BEGIN_MESSAGE_MAP(CSynchroSettingDlg, CDialog)
	ON_BN_CLICKED(IDOK, &CSynchroSettingDlg::OnBnClickedOk)
	ON_WM_CREATE()
	ON_BN_CLICKED(IDC_RADIO1, &CSynchroSettingDlg::OnBnClickedSynchro)
	ON_BN_CLICKED(IDC_RADIO2, &CSynchroSettingDlg::OnBnClickedSynchro)
	ON_BN_CLICKED(IDC_RADIO3, &CSynchroSettingDlg::OnBnClickedSynchro)
	ON_BN_CLICKED(IDC_RADIO4, &CSynchroSettingDlg::OnBnClickedSynchro)
END_MESSAGE_MAP()


// CSynchroSettingDlg message handlers

void CSynchroSettingDlg::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	//UpdateData();	
	OnOK();
}

int CSynchroSettingDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;

	// TODO:  Add your specialized creation code here
	return 0;
}

void CSynchroSettingDlg::OnBnClickedSynchro()
{
	// TODO: Add your control notification handler code here
	UpdateData();
	if( s_choice == 2 )
		GetDlgItem( IDC_EDIT_REFRESH_RATE )->EnableWindow(TRUE);
	else
		GetDlgItem( IDC_EDIT_REFRESH_RATE )->EnableWindow(FALSE);
	UpdateData(FALSE);
}

int CSynchroSettingDlg::getSynchroRefreshRate()
{
	switch(s_choice)
	{
	case 0:
		return 5000;
	case 1:
		return 10000;
	case 2:
		return s_refreshRate*1000;
	case 3:
		return INT_MAX;
	}
}